Skip to content

Grammar of recursive language #757

Answered by ArtifyCZ
ArtifyCZ asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, I have found solution, whitespaces were the problem.

Program = _{ SOI ~ Expr* ~ EOI }

WHITESPACE = _{ " " | "\t" | NEWLINE }

COMMENT = _{ SingleLineComment | MultilineComment }
SingleLineComment = _{ "//" ~ (!NEWLINE ~ ANY)* ~ (NEWLINE | EOI) }
MultilineComment = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }

Expr = { "(" ~ Term+ ~ ")" }

Term = { Expr | Number | String | Sequence | Symbol }

Number = ${ HexNum | BinNum | FloatNum | DecNum }

HexNum = @{ "0x" ~ ASCII_HEX_DIGIT+ }
BinNum = @{ "0b" ~ ("0" | "1")+ }
FloatNum = @{ ("-"? ~ (ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT*) | ("." ~ ASCII_DIGIT+)) }
DecNum = @{ "-"? ~ ASCII_DIGIT+ }

String = @{ QUOTATION_MARK ~ (("\\" ~ QUOTATION_MARK) | (!QUOTA…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ArtifyCZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant