% NAC grammar for N-Address Code (NAC) Intermediate Language % Nikolaos Kavvadias, February 2011 % From the spec, it is not clear if TIL should be priority expression parsed or not, % so this grammar provides both, controlled by this switch % #define PRIORITY keys in out localvar globalvar procedure end keys compounds <= end compounds comments // end comments tokens decnum "\d+" fxpnum "\d+.\d*" end tokens tokens anum "\i+(.\i+)?" end tokens % Direct TXL encoding of the TIL specification grammar - % I don't think any explantions are needed from here on % [NL], [IN] and [EX] on the right are optional pretty-printing cues define program [globalvar_def*] [procedure_def*] end define define globalvar_def globalvar [anum] [id_list] ; [NL] | globalvar [anum] [initializedarray,+] ; [NL] | globalvar [anum] [uninitializedarray,+] ; [NL] end define define procedure_def procedure [ident] '( [arg_list] ') '{ [NL] [localvar_list] [stmt_list] '} end define define arg_list [arg_decl,] end define define arg_decl in [anum] [anum] | in [anum] [uninitializedarray] | out [anum] [anum] | out [anum] [uninitializedarray] end define define localvar_list [localvar_decl*] end define define localvar_decl localvar [anum] [decl_item,+] ; [NL] end define define stmt_list [stmt*] end define define stmt [nac] [NL] | [pcall] [NL] | [ident] : [NL] end define define nac [anum] [id_list] ; | [id_list] <= [anum] [id_list] ; end define define pcall [anum] '( [id_list] ') ; | '( [id_list] ') <= [anum] '( [id_list] ') ; end define define id_list [ident,] end define define decl_item [anum] | [initializedarray] | [uninitializedarray] end define define initializedarray [anum] '[ [ident] '] '= '{ [numeric,] '} end define define uninitializedarray [anum] '[ [ident] '] | [anum] '[ '] end define define ident [anum] | [numeric] end define define numeric - [decnum] | [decnum] | - [fxpnum] | [fxpnum] end define