-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EBNF for customasm syntax #139
Comments
How would we go about describing instruction invocations? They're not context-free -- they're completely mysterious until it's matching time, and are parsed in context of each possible instruction. Meaning if two possible instructions have expression slots in different spots, what is considered an expression is going to change for the same invocation. For example: #ruledef
{
ld {a}, x + 1 => 0x11
ld x + 1, {a} => 0x22
}
x = 0
ld x + 1, x + 1 ; invocation It's undefined what the invocation syntax is until the parsing algorithm runs, which will try to parse it twice: one pass for each rule you declared beforehand. When With that in mind, do you still think it would make sense to keep an EBNF grammar around? Maybe for the other parts of the language? The reason Now, the reason you can also specify numerical |
My argument is that there is a grammar for the metalanguage. It might look something like this, just kind of making it up: letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
| "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
| "c" | "d" | "e" | "f" | "g" | "h" | "i"
| "j" | "k" | "l" | "m" | "n" | "o" | "p"
| "q" | "r" | "s" | "t" | "u" | "v" | "w"
| "x" | "y" | "z" ;
nonzero digit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
digit = nonzero digit | "0" ;
binary digit = "0" | "1" ;
octal digit = binary digit | "2" | "3" | "4" | "5" | "6" | "7" ;
hex digit = decimal digit | "A" | "B" | "C" | "D" | "E" | "F"
| "a" | "b" | "c" | "d" | "e" | "f" ;
character = letter | digit | "_" ;
binary = "0b", binary digit, { binary digit } ;
octal = "0o", octal digit, { octal digit } ;
decimal = nonzero digit, { digit } ;
hex = "0x", hex digit, { hex digit } ;
identifier = ( letter | "_" ), { character } ;
number = [ "-" ], ( binary | octal | decimal | hex ) ;
string = '"', { all characters - '"' }, '"' ;
ruledef directive = "#ruledef", white space, [ identifier ], white space, ruledef arguments ;
ruledef arguments = "{", match expression, { match expression }, "}" ;
match expression = match rule, match body ;
match rule = white space, { all characters }, "=>", white space ;
match body = expression | expressions ;
expressions = "{", white space, expression, { white space, expression }, white space "}" ;
white space = ? white space characters ? ;
all characters = ? all visible characters ? ; With this, define what an I don't think it's worth trying to define the grammar of the instructions defined inside
That's perfectly fine! The grammar for the metalanguage should specify this and that solves it.
This would probably be nice to address. AFAIK wrapping integral typed parameters in braces in the |
I think the confusion with the |
I think some specification of the meta language syntax is still important even if it is not EBNF. For instance when I wrote a syntax definition for Sublime Text, I didn't have a great resource for defining the parser. It is mostly just an approximation based on the wiki and empirical observation. Cf. #105 (comment) |
The customasm meta language has a syntax which can be described in EBNF notation. I have been unable to find any language descriptions matching what EBNF would provide. This is essentially a shorthand description of the parser.
It would help to rule out any syntactic ambiguities, especially as the language evolves. And more importantly I think it would be useful to understand the existing syntax rules. For instance, describing why
asm
block parameters typed by a subrule need enclosing braces (but parameters that are numerically typed must not have enclosing braces): https://github.com/hlorenzi/customasm/wiki/Advanced-rules#asm-blocksExamples should also be tested against the EBNF so that it stays in sync with the parser.
The text was updated successfully, but these errors were encountered: