jBC Programmers Reference Guide · jBC grammar · Grammar files on GitHub

jBC preprocessor grammar: railroad diagrams

Generated from spec/preprocessor.y by spec/tools/grammar_diagrams.py; do not edit. Diagrams read left to right; a track that turns back is a repetition.

FORkeyword(punctuation or operatorIdentifiertoken class (hover for members)resultantrule (click)ident_optionsrule not in this page
How the yacc rules were rewritten

Actions, %prec and error alternatives are dropped. Left recursion such as eols : EOL | eols EOL becomes repetition. Alternatives that share a first or last symbol are factored. These one-line rules are drawn inline where they are used: comp_word, cond_body, def_target, equate_end, expand_param, opt_else, to_or_lit. The diagrams describe the token stream after jpp and the lexer, so ambiguity that the yacc precedence declarations resolve is not shown; see the table below.

program

program_body
program ::= program_body
Used by: start symbol
yacc source
program
    : program_body
    ;

Other rules

Rules used by program, in the order they are first referenced.

program_body

statements
program_body ::= statements+
Used by: if_cond, ifdef_cond, ifndef_cond, macro_body, program
yacc source
program_body
    : program_body statements
    | statements
    | program_body statements error
    | statements error
    ;

statements

token WORDWORDtoken MACROWORDMACROWORD(macro_expand_parameters)token MACROMACROmacro_name{macro_define_parameters}macro_bodytoken ENDMENDMtoken PARAMPARAMtoken DEFAULTDEFAULTtoken PARAMPARAMexpand_wordsEOLend of lineequate_definitionif_condifdef_condifndef_condinclude_optionsjppfilenametoken JPPECHOJPPECHOtoken DEFINEDEFINEtoken WORDWORDword_listEOLend of line
statements
    ::= 'WORD'
     | 'MACROWORD' '(' macro_expand_parameters ')'
     | 'MACRO' macro_name '{' macro_define_parameters '}' macro_body 'ENDM'
     | 'PARAM'
     | 'DEFAULT' 'PARAM' expand_words 'end of line'
     | equate_definition
     | if_cond
     | ifdef_cond
     | ifndef_cond
     | include_options
     | jppfilename
     | 'JPPECHO'
     | 'DEFINE' 'WORD' word_list 'end of line'
Used by: program_body
yacc source
statements
    : WORD
    | MACROWORD {} '(' {} macro_expand_parameters ')'
    | MACRO {} macro_name {} '{' macro_define_parameters '}' {} macro_body ENDM
    | PARAM
    | DEFAULT PARAM {} expand_words EOL
    | equate_definition
    | if_cond
    | ifdef_cond
    | ifndef_cond
    | include_options
    | jppfilename
    | JPPECHO
    | error
    | DEFINE WORD {} word_list EOL
    ;

macro_expand_parameters

expand_words,expand_words
macro_expand_parameters ::= expand_words? ( ',' expand_words? )*
Used by: statements
yacc source
macro_expand_parameters
    : macro_expand_parameters ',' {} expand_param
    | expand_param
    ;

macro_name

token WORDWORD
macro_name ::= 'WORD'+
Used by: statements
yacc source
macro_name
    : macro_name WORD
    | WORD
    ;

macro_define_parameters

token PARAMPARAM,token PARAMPARAM
macro_define_parameters ::= 'PARAM' ( ',' 'PARAM' )*
Used by: statements
yacc source
macro_define_parameters
    : macro_define_parameters ',' PARAM
    | PARAM
    ;

macro_body

program_body
macro_body ::= program_body
Used by: statements
yacc source
macro_body
    : program_body
    ;

expand_words

token WORDWORD
expand_words ::= 'WORD'+
Used by: macro_expand_parameters, statements
yacc source
expand_words
    : expand_words WORD
    | WORD
    ;

equate_definition

token EQUATEEQUATEequate_listEOLend of line;
equate_definition ::= 'EQUATE' equate_list ( 'end of line' | ';' )
Used by: statements
yacc source
equate_definition
    : EQUATE {} equate_list equate_end
    ;

if_cond

token IFIFexpressionprogram_bodytoken ELSEELSEprogram_bodytoken ENDIFENDIF
if_cond ::= 'IF' expression program_body ( 'ELSE' program_body? )? 'ENDIF'
Used by: statements
yacc source
if_cond
    : IF {} expression {} program_body opt_else ENDIF
    ;

ifdef_cond

token IFDEFIFDEFtoken WORDWORDtoken PARAMPARAMprogram_bodytoken ELSEELSEprogram_bodytoken ENDIFENDIF
ifdef_cond ::= 'IFDEF' ( 'WORD' | 'PARAM' ) program_body? ( 'ELSE' program_body? )? 'ENDIF'
Used by: statements
yacc source
ifdef_cond
    : IFDEF def_target {} cond_body opt_else ENDIF
    ;

ifndef_cond

token IFNDEFIFNDEFtoken WORDWORDtoken PARAMPARAMprogram_bodytoken ELSEELSEprogram_bodytoken ENDIFENDIF
ifndef_cond ::= 'IFNDEF' ( 'WORD' | 'PARAM' ) program_body? ( 'ELSE' program_body? )? 'ENDIF'
Used by: statements
yacc source
ifndef_cond
    : IFNDEF def_target {} cond_body opt_else ENDIF
    ;

include_options

token INCLUDEINCLUDEinclude_wordsEOLend of line
include_options ::= 'INCLUDE' include_words 'end of line'
Used by: statements
yacc source
include_options
    : INCLUDE {} include_words EOL
    ;

jppfilename

token JPPFILENAMEJPPFILENAMEtoken WORDWORDtoken WORDWORDEOLend of line
jppfilename ::= 'JPPFILENAME' 'WORD' 'WORD' 'end of line'
Used by: statements
yacc source
jppfilename
    : JPPFILENAME {} WORD WORD EOL
    ;

word_list

token WORDWORD
word_list ::= 'WORD'+
Used by: equate_list, statements
yacc source
word_list
    : word_list WORD
    | WORD
    ;

equate_list

token WORDWORDtoken TOTOtoken LITLITword_list,token WORDWORDtoken TOTOtoken LITLITword_list
equate_list ::= 'WORD' ( 'TO' | 'LIT' ) word_list ( ',' 'WORD' ( 'TO' | 'LIT' ) word_list )*
Used by: equate_definition
yacc source
equate_list
    : equate_list ',' WORD {} to_or_lit {} word_list
    | WORD {} to_or_lit {} word_list
    ;

expression

Starts with one of:

!expression(expression)token WORDWORDtoken PARAMPARAM=#><token WORDWORDtoken PARAMPARAM

Then any number of:

token ANDAND&token OROR|expression
expression
    ::= ( '!' expression
    | '(' expression ')'
    | ( 'WORD' | 'PARAM' ) ( '=' | '#' | '>' | '<' ) ( 'WORD' | 'PARAM' )
    ) ( ( 'AND' | '&' | 'OR' | '|' ) expression )*
Used by: expression, if_cond
yacc source
expression
    : expression AND expression
    | expression '&' expression
    | expression OR expression
    | expression '|' expression
    | '!' expression
    | '(' expression ')'
    | comp_word '=' comp_word
    | comp_word '#' comp_word
    | comp_word '>' comp_word
    | comp_word '<' comp_word
    ;

include_words

token WORDWORD
include_words ::= 'WORD'+
Used by: include_options
yacc source
include_words
    : include_words WORD
    | WORD
    ;

precedence

BindsAssociativityTokens
1left< >
2left# =
3leftAND
4leftOR

Level 1 binds tightest. Taken from the %left, %right and %nonassoc declarations of the grammar.