{"id":13607094,"url":"https://github.com/izackwu/opg-analyzer","last_synced_at":"2025-04-12T11:31:28.196Z","repository":{"id":109747975,"uuid":"264815483","full_name":"izackwu/opg-analyzer","owner":"izackwu","description":"OPG (Operator Precedence Grammar) analyzer/parser. 算符优先文法分析器","archived":false,"fork":false,"pushed_at":"2020-05-24T08:24:38.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-22T02:12:19.499Z","etag":null,"topics":["grammar-parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izackwu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-18T03:27:01.000Z","updated_at":"2021-11-07T11:56:09.000Z","dependencies_parsed_at":"2023-03-09T08:15:14.866Z","dependency_job_id":null,"html_url":"https://github.com/izackwu/opg-analyzer","commit_stats":null,"previous_names":["keithnull/opg-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izackwu%2Fopg-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izackwu%2Fopg-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izackwu%2Fopg-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izackwu%2Fopg-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izackwu","download_url":"https://codeload.github.com/izackwu/opg-analyzer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161277,"owners_count":21057554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grammar-parser"],"created_at":"2024-08-01T19:01:15.521Z","updated_at":"2025-04-12T11:31:26.444Z","avatar_url":"https://github.com/izackwu.png","language":"Go","funding_links":[],"categories":["资源清单"],"sub_categories":["CS2301 (原 CS308) - 编译原理 (A类)"],"readme":"# opg-analyzer\nOPG (Operator Precedence Grammar) analyzer. You may refer to [Wikipedia](https://en.wikipedia.org/wiki/Operator-precedence_grammar) for its definition.\n\n## How to run it?\n\nFirst, make sure Golang has been properly installed on your machine.\n\nUse command `go get` to fetch this repository with ease:\n\n```bash\ngo get github.com/keithnull/opg-analyzer\n```\n\nCheckout to its directory:\n\n```bash\ncd $GOPATH/src/github.com/keithnull/opg-analyzer\n```\n\nBuild it:\n\n```bash\ngo build .\n```\n\nAn executable `opg-analyzer` would now have been generated. Then you can run it with arguments:\n\n```bash\nUsage of opg-analyzer:\n  -grammar string\n         input: OPG file (default \"example_grammar.txt\")\n  -sentences string\n         input: sentences to parse in a file\n  -table string\n        output: OP table file (default \"example_table.txt\")\n```\n\n## Examples\n\nIn file `example_grammar.txt`, there's a simple grammar (note that tokens are separated by spaces):\n\n```\nE -\u003e E + T | T\nT -\u003e T * F | F\nF -\u003e ( E ) | i\n```\n\nIf you pass this grammar to the grammar, it would generate an operator precedence table like this (printed to both `stdout` and file):\n\n```\nThe OP table is:\nTerminals: [( ) i $ + *]\nRelations:\n    (   )   i   $   +   *   \n(   \u003c   =   \u003c       \u003c   \u003c   \n)       \u003e       \u003e   \u003e   \u003e   \ni       \u003e       \u003e   \u003e   \u003e   \n$   \u003c       \u003c   =   \u003c   \u003c   \n+   \u003c   \u003e   \u003c   \u003e   \u003e   \u003c   \n*   \u003c   \u003e   \u003c   \u003e   \u003e   \u003e   \n```\n\nWith that, if you also pass sentences in a file to the program, for example, `exmaple_sentences.txt`:\n\n```\ni + i + i\ni + i * i\n( i + i ) * i\ni * ( i + i\n```\n\nThe parsing result would be:\n\n```\nStart to parse [i + i + i $]\n----------------------------------------------\nIteration Stack                 Input Action\n1         [$]           [i + i + i $] Shift\n2         [$ i]           [+ i + i $] Reduce\n3         [$ X]           [+ i + i $] Shift\n4         [$ X +]           [i + i $] Shift\n5         [$ X + i]           [+ i $] Reduce\n6         [$ X + X]           [+ i $] Reduce\n7         [$ X]               [+ i $] Shift\n8         [$ X +]               [i $] Shift\n9         [$ X + i]               [$] Reduce\n10        [$ X + X]               [$] Reduce\n11        [$ X]                   [$] Accept\n----------------------------------------------\nStart to parse [i + i * i $]\n----------------------------------------------\nIteration Stack                 Input Action\n1         [$]           [i + i * i $] Shift\n2         [$ i]           [+ i * i $] Reduce\n3         [$ X]           [+ i * i $] Shift\n4         [$ X +]           [i * i $] Shift\n5         [$ X + i]           [* i $] Reduce\n6         [$ X + X]           [* i $] Shift\n7         [$ X + X *]           [i $] Shift\n8         [$ X + X * i]           [$] Reduce\n9         [$ X + X * X]           [$] Reduce\n10        [$ X + X]               [$] Reduce\n11        [$ X]                   [$] Accept\n----------------------------------------------\nStart to parse [( i + i ) * i $]\n------------------------------------------------------\nIteration Stack                         Input Action\n1         [$]               [( i + i ) * i $] Shift\n2         [$ (]               [i + i ) * i $] Shift\n3         [$ ( i]               [+ i ) * i $] Reduce\n4         [$ ( X]               [+ i ) * i $] Shift\n5         [$ ( X +]               [i ) * i $] Shift\n6         [$ ( X + i]               [) * i $] Reduce\n7         [$ ( X + X]               [) * i $] Reduce\n8         [$ ( X]                   [) * i $] Shift\n9         [$ ( X )]                   [* i $] Reduce\n10        [$ X]                       [* i $] Shift\n11        [$ X *]                       [i $] Shift\n12        [$ X * i]                       [$] Reduce\n13        [$ X * X]                       [$] Reduce\n14        [$ X]                           [$] Accept\n------------------------------------------------------\nStart to parse [i * ( i + i $]\n--------------------------------------------------\nIteration Stack                     Input Action\n1         [$]             [i * ( i + i $] Shift\n2         [$ i]             [* ( i + i $] Reduce\n3         [$ X]             [* ( i + i $] Shift\n4         [$ X *]             [( i + i $] Shift\n5         [$ X * (]             [i + i $] Shift\n6         [$ X * ( i]             [+ i $] Reduce\n7         [$ X * ( X]             [+ i $] Shift\n8         [$ X * ( X +]             [i $] Shift\n9         [$ X * ( X + i]             [$] Reduce\n10        [$ X * ( X + X]             [$] Reduce\n11        [$ X * ( X]                 [$] Error\n--------------------------------------------------\nFailed to parse sentences:\n invalid sentence: [i * ( i + i $]\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizackwu%2Fopg-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizackwu%2Fopg-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizackwu%2Fopg-analyzer/lists"}